package work.jame.blog.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import work.jame.blog.framework.limit.RequestLimit;
import work.jame.blog.framework.result.Result;
import work.jame.blog.service.UserCommentOperationService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Jame
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/userCommentOperation")
public class UserCommentOperationController {

    @Autowired
    private UserCommentOperationService userCommentOperationService;


    @RequestLimit
    @ApiOperation("给评论点赞")
    @GetMapping("/like")
    public Result<?> likeComment(@RequestParam("commentId") Long commentId) {
        if (userCommentOperationService.likeComment(commentId)) {
            return Result.succeedMessage("点赞成功");
        }
        return Result.fail();
    }

    @RequestLimit
    @ApiOperation("取消给评论点赞")
    @GetMapping("/cancelLike")
    public Result<?> cancelLikeComment(@RequestParam("commentId") Long commentId) {
        if (userCommentOperationService.cancelLikeComment(commentId)) {
            return Result.succeedMessage("已取消点赞");
        }
        return Result.fail();
    }

    @RequestLimit
    @ApiOperation("给评论点不喜欢")
    @GetMapping("/notLike")
    public Result<?> notLikeComment(@RequestParam("commentId") Long commentId) {
        if (userCommentOperationService.notLikeComment(commentId)) {
            return Result.succeed();
        }
        return Result.fail();
    }

    @RequestLimit
    @ApiOperation("取消评论不喜欢")
    @GetMapping("/cancelNotLike")
    public Result<?> cancelNotLikeComment(@RequestParam("commentId") Long commentId) {
        if (userCommentOperationService.cancelNotLikeComment(commentId)) {
            return Result.succeedMessage("已取消不喜欢");
        }
        return Result.fail();
    }


}
